package org.micro.neural.config.store;

import org.micro.neural.URL;
import org.micro.neural.extension.SPI;

import java.util.Map;
import java.util.Set;

/**
 * The Store With Config.
 *
 * @author lry
 **/
@SPI(single = true)
public interface IStore {

    /**
     * The initialize store
     *
     * @param url {@link URL}
     */
    void initialize(URL url);

    /**
     * The batch update or add
     *
     * @param expire expire time
     * @param data   config data
     */
    void batchUpOrAdd(long expire, Map<String, Long> data);

    /**
     * The add Map with key
     *
     * @param moduleKey {@link ModuleKey}
     * @param storeKey  {@link StoreKey}
     * @param data      config data
     */
    void add(ModuleKey moduleKey, StoreKey storeKey, Object data);

    /**
     * The search keys with keyword
     *
     * @param moduleKey {@link ModuleKey}
     * @param keyword   config key keyword
     * @return config key list
     */
    Set<StoreKey> searchKeys(ModuleKey moduleKey, String keyword);

    /**
     * The query Map with key
     *
     * @param moduleKey {@link ModuleKey}
     * @param storeKey  {@link StoreKey}
     * @param clz       config object class
     * @return config object
     */
    <C> C query(ModuleKey moduleKey, StoreKey storeKey, Class<C> clz);

    /**
     * The publish
     *
     * @param moduleKey {@link ModuleKey}
     * @param storeKey  {@link StoreKey}
     * @param data      config data
     */
    void publish(ModuleKey moduleKey, StoreKey storeKey, Object data);

    /**
     * The subscribe by subscribeKey
     *
     * @param moduleKey {@link ModuleKey}
     * @param storeKeys {@link StoreKey} list
     * @param listener  {@link IStoreListener}
     */
    void subscribe(ModuleKey moduleKey, StoreKey[] storeKeys, IStoreListener listener);

    /**
     * The un subscribe by SubscribeListener
     *
     * @param listener {@link IStoreListener}
     */
    void unSubscribe(IStoreListener listener);

    /**
     * The destroy
     */
    void destroy();

}
